package org.imlinker.swtgui;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Dialog;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;

public class MainWindow {

	private List list;
	protected Shell shell;
	private MenuItem aboutItem;

	public MainWindow() {
		display = Display.getDefault();
		createContents();
		initListener();
	}

	private void initListener() {
		aboutItem.addSelectionListener(new SelectionAdapter() {

			@Override
			public void widgetSelected(SelectionEvent e) {
				System.out.println("about");
			}

		});
	}

	/**
	 * Open the window
	 */
	public void open() {
		shell.layout();
		shell.open();

		while (!shell.isDisposed()) {
			if (!display.readAndDispatch())
				display.sleep();
		}
		shell.dispose();
		display.dispose();
	}

	/**
	 * Create contents of the window
	 */
	protected void createContents() {
		shell = new Shell();
		shell.setLayout(new FillLayout());
		shell.setSize(201, 395);
		shell.setText("Linker");

		list = new List(shell, SWT.BORDER);

		final Menu menu = new Menu(shell, SWT.BAR);
		shell.setMenuBar(menu);

		final MenuItem newItemMenuItem = new MenuItem(menu, SWT.CASCADE);
		newItemMenuItem.setText("Account");

		final Menu menu_1 = new Menu(newItemMenuItem);
		newItemMenuItem.setMenu(menu_1);

		final MenuItem newItemMenuItem_3 = new MenuItem(menu_1, SWT.NONE);
		newItemMenuItem_3.setText("Login");

		final MenuItem newItemMenuItem_4 = new MenuItem(menu_1, SWT.NONE);
		newItemMenuItem_4.setText("Exit");

		final MenuItem newItemMenuItem_1 = new MenuItem(menu, SWT.CASCADE);
		newItemMenuItem_1.setText("Action");

		final Menu menu_2 = new Menu(newItemMenuItem_1);
		newItemMenuItem_1.setMenu(menu_2);

		final MenuItem newItemMenuItem_5 = new MenuItem(menu_2, SWT.NONE);
		newItemMenuItem_5.setText("AddBuddy");

		final MenuItem newItemMenuItem_6 = new MenuItem(menu_2, SWT.NONE);
		newItemMenuItem_6.setText("DeleteBuddy");

		new MenuItem(menu_2, SWT.SEPARATOR);

		final MenuItem newItemMenuItem_9 = new MenuItem(menu_2, SWT.NONE);
		newItemMenuItem_9.setText("Say");

		final MenuItem newItemMenuItem_2 = new MenuItem(menu, SWT.CASCADE);
		newItemMenuItem_2.setText("Help");

		final Menu menu_3 = new Menu(newItemMenuItem_2);
		newItemMenuItem_2.setMenu(menu_3);

		aboutItem = new MenuItem(menu_3, SWT.NONE);
		aboutItem.setText("About");
		//
	}

	private final Display display;
}
